package leetcode.comm;

import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;

import java.util.List;

public class ListNode {
    private static ListNode HEAD = new ListNode(0);

    public int val;

    public ListNode next;

    public ListNode(int val) {
        this.val = val;
    }

    public static ListNode generate(int ... values) {
        ListNode temp = HEAD;
        for (int i : values) {
            temp = temp.next = new ListNode(i);
        }
        return HEAD.next;
    }

    @Override
    public String toString() {
        List<Integer> list = Lists.newArrayList();
        for (ListNode n = this; n != null; n = n.next) {
            list.add(n.val);
        }
        return JSONObject.toJSONString(list);
    }

}
